package com.odianyun.hello.web.controller;

import com.odianyun.hello.model.DTO.SuZhouDTO;
import com.odianyun.hello.model.VO.SuZhouVO;
import com.odianyun.hello.service.ISuZhouService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.regex.Pattern;

@RestController
@Api(tags = "苏州景区mongodb")
@RequestMapping("suzhou")
public class SuZhouController {
    @Resource
    private ISuZhouService suZhouService;


    @ApiOperation("添加")
    @PostMapping("save")
    public String Save(@RequestBody SuZhouDTO suZhouDTO){
        suZhouService.save(suZhouDTO);
        return "success";
    }

    @ApiOperation("根据id查找")
    @PostMapping("findById")
    public List<SuZhouDTO> findById(@RequestBody SuZhouDTO suZhouDTO){
        List<SuZhouDTO> listSuZhou = suZhouService.findById(suZhouDTO);
        return  listSuZhou;
    }

    @ApiOperation("查找所有")
    @PostMapping("findAll")
    public List<SuZhouDTO> findAll(){
        List<SuZhouDTO> listSuZhou = suZhouService.findAll();
        return  listSuZhou;
    }

    @ApiOperation("根据name模糊查询")
    @PostMapping("findWithRegex")
    public List<SuZhouDTO> findWithRegex(String patternName){
        List<SuZhouDTO> listSuZhou = suZhouService.findWithRegex(patternName);
        return  listSuZhou;
    }


}
